package com.jx.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jx.dao.FindFuncByDidDao;
import com.jx.dao.FindFuncsDao;
import com.jx.daoimpl.FindFuncByDidDaoimpl;
import com.jx.daoimpl.FindFuncsDaoImpl;
import com.jx.daoimpl.FindSomeDepDaoImpl;
import com.jx.model.Dep;
import com.jx.model.Func;
import com.jx.service.FindAllDepService;
import com.jx.service.FindSomeDepService;
import com.jx.servicrimpl.FindAllDepServiceImpl;
import com.jx.servicrimpl.FindSomeDepServiceImpl;

import net.sf.json.JSONObject;
/**
 * 查找所有部门
 * @author zzzzzzz
 *
 */
public class FindAllDepController extends HttpServlet implements java.io.Serializable{
	FindAllDepService fads=new FindAllDepServiceImpl();
	FindSomeDepService fsds=new FindSomeDepServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		resp.setCharacterEncoding("utf8");
		req.setCharacterEncoding("utf8");
		//获取前台分页
		int page=Integer.parseInt(req.getParameter("page"));
		int pagesize=Integer.parseInt(req.getParameter("rows"));
		int start=(page-1)*pagesize;
		//new一个json对象
		JSONObject json=new JSONObject();
		//获取前台搜索的字符串
		String searchname=req.getParameter("searchname");
		//判断搜索框是否有值，调用方法查询
		if(searchname!=null){
			json=fsds.findSomeDepService(searchname,start,pagesize);
		}else{
			json= fads.findAllDepService(start,pagesize);
		}
		//返回前台
		PrintWriter pw=resp.getWriter();
		pw.write(String.valueOf(json));
		
	}
}
